<div class="problemindexholder" problemindex="C">
 <div class="ttypography">
  <div class="problem-statement">
   <div class="header">
    <div class="title">
     C. The Tag Game
    </div>
    <div class="time-limit">
     <div class="property-title">
      time limit per test
     </div>
     1 second
    </div>
    <div class="memory-limit">
     <div class="property-title">
      memory limit per test
     </div>
     256 megabytes
    </div>
    <div class="input-file">
     <div class="property-title">
      input
     </div>
     standard input
    </div>
    <div class="output-file">
     <div class="property-title">
      output
     </div>
     standard output
    </div>
   </div>
   <div>
    <p>
     Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of
     <span class="tex-span">
      <i>
       n
      </i>
     </span>
     vertices. Vertex
     <span class="tex-font-style-tt">
      1
     </span>
     is the root of the tree.
    </p>
    <p>
     Alice starts at vertex
     <span class="tex-font-style-tt">
      1
     </span>
     and Bob starts at vertex
     <span class="tex-span">
      <i>
       x
      </i>
     </span>
     (
     <span class="tex-span">
      <i>
       x
      </i>
      ≠ 1
     </span>
     ). The moves are made in turns, Bob goes first. In one move one can either stay at the current vertex or travel to the neighbouring one.
    </p>
    <p>
     The game ends when Alice goes to the same vertex where Bob is standing. Alice wants to minimize the total number of moves and Bob wants to maximize it.
    </p>
    <p>
     You should write a program which will determine how many moves will the game last.
    </p>
   </div>
   <div class="input-specification">
    <div class="section-title">
     Input
    </div>
    <p>
     The first line contains two integer numbers
     <span class="tex-span">
      <i>
       n
      </i>
     </span>
     and
     <span class="tex-span">
      <i>
       x
      </i>
     </span>
     (
     <span class="tex-span">
      2 ≤
      <i>
       n
      </i>
      ≤ 2·10
      <sup class="upper-index">
       5
      </sup>
     </span>
     ,
     <span class="tex-span">
      2 ≤
      <i>
       x
      </i>
      ≤
      <i>
       n
      </i>
     </span>
     ).
    </p>
    <p>
     Each of the next
     <span class="tex-span">
      <i>
       n
      </i>
      - 1
     </span>
     lines contains two integer numbers
     <span class="tex-span">
      <i>
       a
      </i>
     </span>
     and
     <span class="tex-span">
      <i>
       b
      </i>
     </span>
     (
     <span class="tex-span">
      1 ≤
      <i>
       a
      </i>
      ,
      <i>
       b
      </i>
      ≤
      <i>
       n
      </i>
     </span>
     ) — edges of the tree. It is guaranteed that the edges form a valid tree.
    </p>
   </div>
   <div class="output-specification">
    <div class="section-title">
     Output
    </div>
    <p>
     Print the total number of moves Alice and Bob will make.
    </p>
   </div>
   <div class="sample-tests">
    <div class="section-title">
     Examples
    </div>
    <div class="sample-test">
     <div class="input">
      <div class="title">
       Input
      </div>
      <pre>4 3<br/>1 2<br/>2 3<br/>2 4<br/></pre>
     </div>
     <div class="output">
      <div class="title">
       Output
      </div>
      <pre>4<br/></pre>
     </div>
     <div class="input">
      <div class="title">
       Input
      </div>
      <pre>5 2<br/>1 2<br/>2 3<br/>3 4<br/>2 5<br/></pre>
     </div>
     <div class="output">
      <div class="title">
       Output
      </div>
      <pre>6<br/></pre>
     </div>
    </div>
   </div>
   <div class="note">
    <div class="section-title">
     Note
    </div>
    <p>
     In the first example the tree looks like this:
    </p>
    <center>
     <img class="tex-graphics" src="/predownloaded/86/48/8648a08b6e41f4dcc0e7f1095ad78ab38d52b1b0.png" style="max-width: 100.0%;max-height: 100.0%;"/>
    </center>
    <p>
     The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex
     <span class="tex-font-style-tt">
      3
     </span>
     during all the game. So here are the moves:
    </p>
    <p>
     <span class="tex-font-style-bf">
      B
     </span>
     : stay at vertex
     <span class="tex-font-style-tt">
      3
     </span>
    </p>
    <p>
     <span class="tex-font-style-bf">
      A
     </span>
     : go to vertex
     <span class="tex-font-style-tt">
      2
     </span>
    </p>
    <p>
     <span class="tex-font-style-bf">
      B
     </span>
     : stay at vertex
     <span class="tex-font-style-tt">
      3
     </span>
    </p>
    <p>
     <span class="tex-font-style-bf">
      A
     </span>
     : go to vertex
     <span class="tex-font-style-tt">
      3
     </span>
    </p>
    <p>
     In the second example the tree looks like this:
    </p>
    <center>
     <img class="tex-graphics" src="/predownloaded/d8/d2/d8d23c03485ae75cd6ddbd3297172d58782196bd.png" style="max-width: 100.0%;max-height: 100.0%;"/>
    </center>
    <p>
     The moves in the optimal strategy are:
    </p>
    <p>
     <span class="tex-font-style-bf">
      B
     </span>
     : go to vertex
     <span class="tex-font-style-tt">
      3
     </span>
    </p>
    <p>
     <span class="tex-font-style-bf">
      A
     </span>
     : go to vertex
     <span class="tex-font-style-tt">
      2
     </span>
    </p>
    <p>
     <span class="tex-font-style-bf">
      B
     </span>
     : go to vertex
     <span class="tex-font-style-tt">
      4
     </span>
    </p>
    <p>
     <span class="tex-font-style-bf">
      A
     </span>
     : go to vertex
     <span class="tex-font-style-tt">
      3
     </span>
    </p>
    <p>
     <span class="tex-font-style-bf">
      B
     </span>
     : stay at vertex
     <span class="tex-font-style-tt">
      4
     </span>
    </p>
    <p>
     <span class="tex-font-style-bf">
      A
     </span>
     : go to vertex
     <span class="tex-font-style-tt">
      4
     </span>
    </p>
   </div>
  </div>
  <p>
  </p>
 </div>
</div>
